//index.js
//获取应用实例
var app = getApp()

Page({
  data: {
    toView: "",
    motto: 'MiHome_Store',
    userInfo: {},
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 100,
    newgoods: [
      {
        "hg_pic": "https://images.unsplash.com/photo-1551259054-ecc962e65704?auto=format&fit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OXx8JUU1JUIzJUE4JUU3JTlDJTg5JUU1JUIxJUIxfGVufDB8fDB8fHww"
      }, {
        "hg_pic": "https://images.unsplash.com/photo-1454496522488-7a8e488e8606?auto=format&fit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8M3x8bW91bnRhaW58ZW58MHx8MHx8fDA%3D"
      }, {
        "hg_pic": "https://images.unsplash.com/photo-1542662565-7e4b66bae529?auto=format&fit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fG1vdW50YWlufGVufDB8fDB8fHww"
      }
    ],
    hotgoods: [ {
      "hg_pic": "https://images.unsplash.com/photo-1454496522488-7a8e488e8606?auto=formatfit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8M3x8bW91bnRhaW58ZW58MHx8MHx8fDA%3D"}
    ],
    banner_BackGround: [
      {
        "banner": [
          {
            "pic_url": "https://images.unsplash.com/photo-1544198365-f5d60b6d8190?auto=format&fit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTl8fG1vdW50YWlufGVufDB8fDB8fHww",
          },
          {
            "pic_url": "https://images.unsplash.com/photo-1483728642387-6c3bdd6c93e5?auto=format&fit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTF8fG1vdW50YWlufGVufDB8fDB8fHww",
          },
          {
            "pic_url": "https://images.unsplash.com/photo-1439405326854-014607f694d7?auto=format&fit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Nnx8c2VhfGVufDB8fDB8fHww",
          },
          {
            "pic_url": "https://images.unsplash.com/photo-1457195740896-7f345efef228?auto=format&fit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTJ8fHNlYXxlbnwwfHwwfHx8MA%3D%3D",
          },
          {
            "pic_url": "https://images.unsplash.com/photo-1597218386369-c7761ff9b4eb?auto=format&fit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8NHx8bG93fGVufDB8fDB8fHww",
          }
        ]
      },
      {
        "banner": []
      }
    ]
  },
  getData(){
    let that =this
    wx.request({
      url: 'http://localhost:8081/student/student01',
      success(res){
        console.log("请求成功",res.data)
        that.setData({
          dataList:res.data
        })
      },
      fail(res){
        console.log("请求失败",res)
      }
    })
  },
  //提交数据到java后台
  tijiao(){
    wx.request({
      url: 'http://localhost:8082/student/demo2',
      data:{
         age:28
      },
      success(res){
        console.log("上传数据成功",res)
      },
      fail(res){
        console.log("上传失败",res)
      }
    })
  },
  redirectToPage: function () {
    // 使用 wx.navigateTo 跳转到目标页面，保留当前页面
    // 使用 wx.redirectTo 跳转到目标页面，关闭当前页面
    wx.navigateTo({
      url: '/pages/VirtualSelfie/scene/scene'
    })
  },
  onPullDownRefresh: function () {
    console.log('onPullDownRefresh')
  },
  scroll: function (e) {
    if (this.data.toView == "top") {
      this.setData({
        toView: ""
      })
    }
  },

  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  vr:function(){
    wx.navigateTo({
      url: '../detail/detail',
    })
  },
  tap: function () {
    this.setData({
      toView: "top"
    })
  },
  onLoad: function () {

    //调用应用实例的方法获取全局数据
    var that = this;
   

    //通过原生调取数据
    wx.request({
      // url: 'https://wxapi.hotapp.cn/api/get', 错误提示显示小程序试图从 https://wxapi.hotapp.cn/api/get 获取数据时遇到了连接关闭的问题,不知道后面是否要用，所以我直接注释了——瑞
      data: {
        appkey: 'hotapp25781921',
        key: 'hot1'
      },
      method: "GET",
      header: {
        "content-type": "application/json"
      },
      success: function (a) {
        console.log(a)
        return "function" == typeof b && b(a.data)
      },
      fail: function (err) {
        console.log(err)
        return "function" == typeof b && b(!1)
      }
    })
    //fecth调用
    var fekchobj = {
      R_GET: function (url, params) {
        if (params) {
          let paramsArray = []
          Object.keys(params).forEach(key => paramsArray.push(key + '=' + encodeURIComponent(params[key])))
          if (url.search(/\?/) === -1) {
            url += '?' + paramsArray.join('&')

          } else {
            url += '&' + paramsArray.join('&')
          }
        }

        return new Promise(function (resolve, reject) {
          fetch(url)
            .then((response) => {
              if (response.ok) {
                return response.json()

              } else {
                reject('服务器繁忙，请稍后再试；\r\nCode:' + response.status)
              }
            })
            .then((response) => {
              if (response && response.status) {
                resolve(response)//response.status 是与服务器端的约定，非0就是错误
              } else {
                reject(response)//response也是与服务器端的约定
              }
            })
            .catch((err) => {
              reject(_parseErrorMsg(err))
            })
        })
      }
    }
    //监测错误
    try{
     
    }catch(e){
      console.log(e)
    }
   console.log(fekchobj)
    


  }
})
